package com.sg.hms.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sg.hms.Service.H_ApplicationService;
import com.sg.hms.ServiceImpl.H_ApplicationServiceImpl;

import net.sf.json.JSONObject;
/**
 * 
 * @author 王奇霞
 *
 */
public class Search_h_MoneyApplicationController extends HttpServlet{
     
	private H_ApplicationService appliservice=new H_ApplicationServiceImpl();
	@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	doPost(req, resp);
    }
     @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	req.setCharacterEncoding("utf-8");
    	resp.setCharacterEncoding("utf-8");
    	String madate=req.getParameter("maDate");
    	String maState=req.getParameter("maState");
    	//System.out.println(maState);
    	//System.out.println(madate);
        PrintWriter pw=resp.getWriter();
    	int page=Integer.parseInt(req.getParameter("page"));
     	int pagesize=Integer.parseInt(req.getParameter("rows"));
     	int start=(page-1)*pagesize;
        JSONObject json=null;
        if(maState==null){
        	maState="所有";
        }
        if(madate==null||madate==""){
        	json=appliservice.searchmoneyapplication(start, pagesize,maState);
        }else{
        	json=appliservice.searchmoneyapplication(start, pagesize,madate,maState);
        }
       /* if(madate==null){
        	json=appliservice.searchmoneyapplication(start, pagesize);
        }else{
        	json=appliservice.searchmoneyapplication(start, pagesize,madate);
        }*/	
        pw.write(json.toString());
    }
}
